#include "zf_common_headfile.h"
#include "DisPlay.h"
#include "Image.h"
extern uint8_t My_Image[90][155]; 
extern int Left_Encoder;
extern int Right_Encoder;
extern double fps;
//目前使用的老板本不可调参的菜单
Typedef_Menue MENUE[10]={
    {"Page_1",Page_1},
    {"Page_2",Page_2},
    {"Page_3",Page_3},
    {"Page_4",Page_4},
    {"Page_5",Page_5},
    {"Page_6",Page_6},
    {"Page_7",Page_7},
    {"ShiZi_Page",ShiZi_Page},  
    {"Huandao_Left_Page",Huandao_Left_Page},
    {"Huandao_Left_Page",Huandao_Left_Page2},   
};

/***********************可调参菜单数据****************************************/
Typedef_Menue Change_Menue[10]={
    {"Change_Pid",Change_Pid},
    {"Change_Speed",Change_Speed},
    {"Change_YuanSu_Flag",Change_YuanSu_Flag},
    {"Change_TuXiang",Change_TuXiang},
};
//菜单坐标
Typedef_Index Menue_Chos[Page_Num_MAX]={
        {0,130,130,130,210,130},
        {0,150,130,150,210,150},
        {0,170,130,170,210,170},
        {0,190,130,190,210,190},
        {0,210,130,210,210,210},
        {0,230,130,230,210,230},
        {0,250,130,250,210,250},
        {0,270,130,270,210,270},
        {0,290,130,290,210,290},
};
Typedef_Float_Num PID[Page_Num_MAX]={
    {"L_Kp",&Moter_Left.Kp},
    {"L_Ki",&Moter_Left.Ki},
    {"L_Kd",&Moter_Left.Kd},
    {"R_Kp",&Moter_Right.Kp},
    {"R_Ki",&Moter_Right.Ki},
    {"R_Kd",&Moter_Right.Kd},
    {"S_Kp",&Servo.Kp},
    {"S_Ki",&Servo.Ki},
    {"S_Kd",&Servo.Kd},   
};
Typedef_Int_Num Speed[Page_Num_MAX]={
    {"Auto_Speed_Flag",&Auto_Speed_Flag},
    {"Speed",&Speed_Target},
    {"BiZhang_Max_Speed",&BiZhang_Max_Speed},
    {"Right_Huandao_Max_Speed",&Right_Huandao_Max_Speed},
    {"Left_Huandao_Max_Speed",&Left_Huandao_Max_Speed},  
    {"Podao_Max_Speed",&Podao_Max_Speed},  
    {"WanDao_Max_Speed",&WanDao_Max_Speed},
    {"ZhiDao_Speed",&ZhiDao_Speed},
};
Typedef_Int_Num YuanSu_Flag[Page_Num_MAX]={
    {"Shizi_Key",&Shizi_Key}, 
    {"Banma_Key",&Banma_Key},
    {"Huandao_Key",&Huandao_Key},
    {"Podao_Key",&Podao_Key},
    {"WanDao_Key",&WanDao_Key},
    {"BiZhang_Key",&BiZhang_Key},
};
Typedef_Int_Num DAjin[Page_Num_MAX]={
    {"VALUE_Key",&VALUE_Key}, 
    {"threshold_value",&threshold_value},
    {"brightness",&brightness},
};
/*********************可调参菜单数据*************************/
//读取拨码开关数据
int Get_SwitchValue()
{
    int Switch_Satse=0;
    if(gpio_get_level(SWITCH_0)==0 && gpio_get_level(SWITCH_1)==0)
    {
        Switch_Satse=1;
    }
    else if(gpio_get_level(SWITCH_0)==1 && gpio_get_level(SWITCH_1)==0)
    {
        Switch_Satse=2;
    }
    else if(gpio_get_level(SWITCH_0)==0 && gpio_get_level(SWITCH_1)==1)
    {
        Switch_Satse=3;
    }
    else if(gpio_get_level(SWITCH_0)==1 && gpio_get_level(SWITCH_1)==1)
    {
        Switch_Satse=4;
    }
    return Switch_Satse;
}
//读取按键数据
int Get_KeyValue()
{
    int Key_Value=0;
    if(gpio_get_level(KEY_0)==0)
    {
        system_delay_ms(20);
        while(gpio_get_level(KEY_0)==0);
        system_delay_ms(20);
        Key_Value=1;
    }
    else if(gpio_get_level(KEY_1)==0)
    {
        system_delay_ms(20);
        while(gpio_get_level(KEY_1)==0);
        system_delay_ms(20);
        Key_Value=2;
    }
    else if(gpio_get_level(KEY_2)==0)
    {
        system_delay_ms(20);
        while(gpio_get_level(KEY_2)==0);
        system_delay_ms(20);
        Key_Value=3;
    }
    else if(gpio_get_level(KEY_3)==0)
    {
        system_delay_ms(20);
        while(gpio_get_level(KEY_3)==0);
        system_delay_ms(20);
        Key_Value=4;
    }
    return Key_Value;
}
/*********************************************图像上显示的特殊拐点*****************************************************************/
//在屏幕上显示+
void Draw_X_In_Point_IPS200(uint8(*image)[image_w], uint8 point_y, uint8 point_x, uint16 colour)
{
    if(((point_y - 2) <= Y_Border_Max) && ((point_y - 2) >= Y_Border_Min) && ((point_x - 2) <= X_Border_Max) && ((point_x - 2) >= X_Border_Min))
    {
        ips200_draw_point(point_x - 2, point_y - 2, colour);
    }
    if(((point_y - 1) <= Y_Border_Max) && ((point_y - 1) >= Y_Border_Min) && ((point_x - 1) <= X_Border_Max) && ((point_x - 1) >= X_Border_Min))
    {
        ips200_draw_point(point_x - 1, point_y - 1, colour);
    }
    if(((point_y + 1) <= Y_Border_Max) && ((point_y + 1) >= Y_Border_Min) && ((point_x - 1) <= X_Border_Max) && ((point_x - 1) >= X_Border_Min))
    {
        ips200_draw_point(point_x - 1, point_y + 1, colour);
    }
    if(((point_y + 2) <= Y_Border_Max) && ((point_y + 2) >= Y_Border_Min) && ((point_x - 2) <= X_Border_Max) && ((point_x - 2) >= X_Border_Min))
    {
        ips200_draw_point(point_x - 2, point_y + 2, colour);
    }
    if(((point_y - 2) <= Y_Border_Max) && ((point_y - 2) >= Y_Border_Min) && ((point_x + 2) <= X_Border_Max) && ((point_x + 2) >= X_Border_Min))
    {
        ips200_draw_point(point_x + 2, point_y - 2, colour);
    }
    if(((point_y - 1) <= Y_Border_Max) && ((point_y - 1) >= Y_Border_Min) && ((point_x + 1) <= X_Border_Max) && ((point_x + 1) >= X_Border_Min))
    {
        ips200_draw_point(point_x + 1, point_y - 1, colour);
    }
    if(((point_y + 2) <= Y_Border_Max) && ((point_y + 2) >= Y_Border_Min) && ((point_x + 2) <= X_Border_Max) && ((point_x + 2) >= X_Border_Min))
    {
        ips200_draw_point(point_x + 2, point_y + 2, colour);
    }
    if(((point_y + 1) <= Y_Border_Max) && ((point_y + 1) >= Y_Border_Min) && ((point_x + 1) <= X_Border_Max) && ((point_x + 1) >= X_Border_Min))
    {
        ips200_draw_point(point_x + 1, point_y + 1, colour);
    }
}
//在屏幕上打印出特殊点
void Show_Special_point()
{
    // ips200_clear();
   if(R_Left_Turn_Up_Point_Flag_1==1)
   {
        Draw_X_In_Point_IPS200(My_Image,R_Left_Turn_Up_Point_1[1],R_Left_Turn_Up_Point_1[0],RGB565_BLUE);
   }
   else if(R_Up_Turn_Right_Point_Flag_1==1)
   {
        Draw_X_In_Point_IPS200(My_Image,R_Up_Turn_Right_Point_1[1],R_Up_Turn_Right_Point_1[0],RGB565_BLUE);
   }
   else if(L_Right_Turn_Up_Point_Flag_1==1)
   {
        Draw_X_In_Point_IPS200(My_Image,L_Right_Turn_Up_Point_1[1],L_Right_Turn_Up_Point_1[0],RGB565_BLUE);
   }
   else if(L_Up_Turn_Left_Point_Flag_1==1)
   {
        Draw_X_In_Point_IPS200(My_Image,L_Up_Turn_Left_Point_1[1],L_Up_Turn_Left_Point_1[0],RGB565_BLUE);
   }
   else if(L_Arc_Turn_Point_Flag==1)
   {
        if(L_Arc_Turn_Point_Num==1)
        {
            Draw_X_In_Point_IPS200(My_Image,R_Arc_Turn_Point[0][1],R_Arc_Turn_Point[0][0],RGB565_RED);
        }
        else if(L_Arc_Turn_Point_Num==2)
        {
            Draw_X_In_Point_IPS200(My_Image,R_Arc_Turn_Point[1][1],R_Arc_Turn_Point[1][0],RGB565_GREEN);
        }
        else if(L_Arc_Turn_Point_Num==3)
        {
            Draw_X_In_Point_IPS200(My_Image,R_Arc_Turn_Point[2][1],R_Arc_Turn_Point[2][0],RGB565_YELLOW);
        }
   }
   else if(R_Arc_Turn_Point_Flag)
   {
     if(R_Arc_Turn_Point_Num==1)
        {
            Draw_X_In_Point_IPS200(My_Image,L_Arc_Turn_Point[0][1],L_Arc_Turn_Point[0][0],RGB565_RED);
        }
        else if(R_Arc_Turn_Point_Num==2)
        {
            Draw_X_In_Point_IPS200(My_Image,L_Arc_Turn_Point[1][1],L_Arc_Turn_Point[1][0],RGB565_GREEN);
        }
        else if(R_Arc_Turn_Point_Num==3)
        {
            Draw_X_In_Point_IPS200(My_Image,L_Arc_Turn_Point[2][1],L_Arc_Turn_Point[2][0],RGB565_YELLOW);
        }
   }
}
/*********************************************图像上显示边线*****************************************************************/
//屏幕显示边线
//1:左右一维边线 2：二维边线 3：显示中线
void Show_Line(uint8 gade)
{
    // ips200_clear();
    //边线
    int i=0;
    if(gade==1)
    {
        for(i=hightest;i<image_h-2;i++)
        {
            if(l_border[i]>=border_min && r_border[i]<border_max)
            {
                ips200_draw_point(l_border[i],i,RGB565_RED);
                ips200_draw_point(r_border[i],i,RGB565_GREEN);
            }
        }
    }
    else if(gade==2)
    {   
        //二维边线
         for(i=0;i<data_stastics_l;i++ )
        {
            if(points_l[i][0] < border_max && points_l[i][0] >border_min && points_l[i][1] > 1 && points_l[i][1] < image_h)
            {
                ips200_draw_point(points_l[i][0], points_l[i][1], RGB565_GREEN);
            }
        }
        for(i=0;i<data_stastics_r;i++ )
        {
            if(points_r[i][0] < border_max && points_r[i][0] > border_min && points_r[i][1] > 1 && points_r[i][1] < image_h)
            {
                ips200_draw_point(points_r[i][0], points_r[i][1], RGB565_BLUE);
            }
        }
    }
    else if(gade==3)
    {
       for(i=hightest;i<image_h-2;i++)
        {
            ips200_draw_point(center_line[i],i,RGB565_YELLOW);
        }
    }
    else if(gade==4)
    {
        //空
    }
}
/*********************************************通用的参数的参数*****************************************************************/
//特殊点
void Page_1(void)
{
    ips200_show_string(0,130,"L_Up_T_Le_Flag_1");ips200_show_int(170,130,L_Up_Turn_Left_Point_Flag_1,1);
    ips200_show_string(0,150,"L_R_T_Up_Flag_1");ips200_show_int(170,150,L_Right_Turn_Up_Point_Flag_1,1);
    ips200_show_string(0,170,"R_Up_T_R_Flag_1");ips200_show_int(170,170,R_Up_Turn_Right_Point_Flag_1,1);
    ips200_show_string(0,190,"R_L_T_Up_Flag_1");ips200_show_int(170,190,R_Left_Turn_Up_Point_Flag_1,1);
    ips200_show_string(0,210,"L_Arc_Turn_Flag");ips200_show_int(170,210,L_Arc_Turn_Point_Flag,1);
    ips200_show_string(0,230,"L_Arc_Turn_Num");ips200_show_int(170,230,L_Arc_Turn_Point_Num,1);
    ips200_show_string(0,250,"R_Arc_Turn_Flag");ips200_show_int(170,250,R_Arc_Turn_Point_Flag,1);
    ips200_show_string(0,270,"R_Arc_Turn_Num");ips200_show_int(170,270,R_Arc_Turn_Point_Num,1);
}
void Page_2(void)
{
    ips200_show_string(0,130,"ShiZi_Flag2");ips200_show_int(170,130,ShiZi_Flag2,1);
    ips200_show_string(0,150,"BanMa_Flag");ips200_show_int(170,150,BanMa_Flag,1);
    ips200_show_string(0,170,"WanDao_Flag");ips200_show_int(170,170,WanDao_Flag,1);
    ips200_show_string(0,190,"ZhiDao_Flag");ips200_show_int(170,190,ZhiDao_Flag,1);
    ips200_show_string(0,210,"HuanDao_Flag");ips200_show_int(170,210,HuanDao_Flag,1);
    ips200_show_string(0,230,"BiZhang_Flag");ips200_show_int(170,230,BiZhang_Flag,1);
    ips200_show_string(0,250,"PoDao_Flag");ips200_show_int(170,250,PoDao_Flag,1);
    ips200_show_string(0,270,"HuanDao_Stas");ips200_show_int(170,270,HuanDao_Stas,1);
}
void Page_3(void)
{
    ips200_show_string(0,130,"Left_Encoder");ips200_show_int(170,130,Left_Encoder,5);
    ips200_show_string(0,150,"Right_Encoder");ips200_show_int(170,150,Right_Encoder,5);
    ips200_show_string(0,170,"Mid_Error");ips200_show_float(170,170,Mid_Error,2,2);
    ips200_show_string(0,190,"Angle");ips200_show_int(170,190,Servo_Agle,5);
    ips200_show_string(0,210,"Left_PWM");ips200_show_int(170,210,Left_OUT,5);
    ips200_show_string(0,230,"Right_PWM");ips200_show_int(170,230,Right_OUT,5);
    ips200_show_string(0,250,"CAR_RUN");ips200_show_int(170,250,CAR_RUN,1);
}
void Page_4(void)
{
    // ips200_show_string(0,110,"Left_Wite_Line0");ips200_show_int(170,110,hightest,5);
    // ips200_show_string(0,130,"Left_Wite_Line0");ips200_show_int(170,130,Longest_Left_Wite_Line[0],5);
    // ips200_show_string(0,150,"Left_Wite_Line1");ips200_show_int(170,150,Longest_Left_Wite_Line[1],5);
    // ips200_show_string(0,170,"Right_Wite_Line0");ips200_show_int(170,170,Longest_Right_Wite_Line[0],5);
    // ips200_show_string(0,190,"Right_Wite_Line1");ips200_show_int(170,190,Longest_Right_Wite_Line[1],5);
    // ips200_show_string(0,210,"start_point_L_X");ips200_show_int(170,210,start_point_l[0],3);
    // ips200_show_string(0,230,"start_point_L_Y");ips200_show_int(170,230,start_point_l[1],3);
    // ips200_show_string(0,250,"start_point_R_X");ips200_show_int(170,250,start_point_r[0],3);
    // ips200_show_string(0,270,"start_point_R_Y");ips200_show_int(170,270,start_point_r[1],3);
    //  ips200_show_string(0,290,"Max_Row_Dif_Line_Num");ips200_show_int(170,290,Max_Row_Dif_Line_Num,2);
    ips200_show_string(0,110,"Left_Wite_Line0");ips200_show_int(170,110,hightest,5);
    ips200_show_string(0,130,"Left_Wite_Line0");ips200_show_int(170,130,Longest_Left_Wite_Line[0],5);
    ips200_show_string(0,150,"Left_Wite_Line1");ips200_show_int(170,150,Longest_Left_Wite_Line[1],5);
    ips200_show_string(0,170,"Left_Slope_A");ips200_show_float(170,170,Left_Slope_A,2,5);
    ips200_show_string(0,190,"Left_Slope_B");ips200_show_float(170,190,Left_Slope_B,2,5);
    ips200_show_string(0,210,"Left_Slope_All");ips200_show_float(170,210,Left_Slope_All,2,5);
    ips200_show_string(0,230,"Right_Slope_A");ips200_show_float(170,230,Right_Slope_A,2,5);
    ips200_show_string(0,250,"Right_Slope_B");ips200_show_float(170,250,Right_Slope_B,2,5);
    ips200_show_string(0,270,"Right_Slope_All");ips200_show_float(170,270,Right_Slope_All,2,5);
     ips200_show_string(0,290,"Last_Curvature_Value");ips200_show_float(170,290,Last_Curvature_Value,2,5);
}
void Page_5(void)
{
    ips200_show_string(0,130,"R_Border_Point_Num");ips200_show_int(170,130,R_Border_Point_Num,3);
    ips200_show_string(0,150,"R_UP_Border_Point_Num");ips200_show_int(170,150,R_UP_Border_Point_Num,3);
    ips200_show_string(0,170,"L_Border_Point_Num");ips200_show_int(170,170,L_Border_Point_Num,3);
    ips200_show_string(0,190,"L_UP_Border_Point_Num");ips200_show_int(170,190,L_UP_Border_Point_Num,3);
    ips200_show_string(0,210,"Relative_Border_Num");ips200_show_int(170,210,Relative_Border_Point_Num,2);
    ips200_show_string(0,230,"Left_S");ips200_show_float(170,230,Left_S,2,3);
    ips200_show_string(0,250,"Right_S");ips200_show_float(170,250,Right_S,2,3);
    ips200_show_string(0,270,"LianXu_Left");ips200_show_int(170,270,LianXu_Left,2);
    ips200_show_string(0,290,"LianXu_Right");ips200_show_int(170,290,LianXu_Right,2);
}
void Page_6(void)
{
    ips200_show_string(0,130,"Left_Up_Point");ips200_show_int(170,130,Left_Up_Point,3);
    ips200_show_string(0,150,"Left_Down_Point");ips200_show_int(170,150,Left_Down_Point,3);
    ips200_show_string(0,170,"Right_Up_Point");ips200_show_int(170,170,Right_Up_Point,3);
    ips200_show_string(0,190,"Right_Down_Point");ips200_show_int(170,190,Right_Down_Point,3);
    ips200_show_string(0,210,"Black_Flag");ips200_show_int(170,210,Black_Flag,2);
    ips200_show_string(0,230,"HuanDao_Stas");ips200_show_int(170,230,HuanDao_Stas,2);
    ips200_show_string(0,250,"Left_ZhiDao_Flag");ips200_show_int(170,250,Left_ZhiDao_Flag,2);
    ips200_show_string(0,270,"Right_ZhiDao_Flag");ips200_show_int(170,270,Right_ZhiDao_Flag,2);
    // ips200_show_string(0,290,"LianXu_Right");ips200_show_int(170,290,LianXu_Right,1);
}
void Page_7(void)
{
    // if(CAR_RUN==0)
    // {
    //     ips200_show_gray_image(0, 80, rgay_image, 160, 70);
    // }
    ips200_show_string(0,130,"Left_Encoder");ips200_show_int(170,130,Left_Encoder,5);
    ips200_show_string(0,150,"Right_Encoder");ips200_show_int(170,150,Right_Encoder,5);
    ips200_show_string(0,170,"FJ_Pitch");ips200_show_float(170,170,FJ_Pitch,3,2);
    ips200_show_string(0,190,"Right_Monotonicity");ips200_show_int(170,190,Right_Monotonicity,4);
    ips200_show_string(0,210,"Right_Vpoint");ips200_show_int(170,210,Right_Vpoint,2);
    ips200_show_string(0,230,"Right_A");ips200_show_int(170,230,Right_A[1],2);
    ips200_show_string(0,250,"Left_V");ips200_show_int(170,250,Left_V[1],2);
    ips200_show_string(0,270,"HuanDao_Stas");ips200_show_int(170,270,HuanDao_Stas,2);
    // ips200_show_string(0,290,"Black_Flag");ips200_show_int(170,290,Black_Flag,2);
}
/*********************************************元素判断的参数*****************************************************************/
//十字拐点
void ShiZi_Page(void)
{
    ips200_show_string(0,130,"L_Up_T_Le_Flag_1");ips200_show_int(170,130,L_Up_Turn_Left_Point_Flag,1);
    ips200_show_string(0,150,"L_R_T_Up_Flag_1");ips200_show_int(170,150,L_Right_Turn_Up_Point_Flag,1);
    ips200_show_string(0,170,"R_Up_T_R_Flag_1");ips200_show_int(170,170,R_Up_Turn_Right_Point_Flag,1);
    ips200_show_string(0,190,"R_L_T_Up_Flag_1");ips200_show_int(170,190,R_Left_Turn_Up_Point_Flag,1);
    ips200_show_string(0,210,"L_Up_T_L_Point_1");ips200_show_int(170,210,L_Up_Turn_Left_Point_Position_1,3);
    ips200_show_string(0,230,"L_R_T_Up_Point_1");ips200_show_int(170,230,L_Right_Turn_Up_Point_Position_1,3);
    ips200_show_string(0,250,"R_U_T_Rt_Point_1");ips200_show_int(170,250,R_Up_Turn_Right_Point_Position_1,3);
    ips200_show_string(0,270,"R_L_T_Up_Point_1");ips200_show_int(170,270,R_Left_Turn_Up_Point_Position_1,3);
}
//左环岛的拐点
void Huandao_Left_Page(void)
{
    ips200_show_string(0,130,"R_Arc_Turn_Po_Flag");ips200_show_int(170,130,R_Arc_Turn_Point_Flag,1);
    ips200_show_string(0,150,"R_Arc_Turn_Po_Num");ips200_show_int(170,150,R_Arc_Turn_Point_Num,1);
    ips200_show_string(0,170,"R_Border_Point_Num");ips200_show_int(170,170,R_Border_Point_Num,3);
    ips200_show_string(0,190,"LianXu_Left");ips200_show_int(170,190,LianXu_Left,3);
    ips200_show_string(0,210,"LianXu_Right");ips200_show_int(170,210,LianXu_Right,3);
    ips200_show_string(0,230,"R_Arc_Turn_Point");ips200_show_int(170,230,R_Arc_Turn_Point[0][1],3);
    ips200_show_string(0,250,"R_Arc_Turn_Point");ips200_show_int(170,250,R_Arc_Turn_Point[1][1],3);
    // ips200_show_string(0,250,"R_U_T_Rt_Point_1");ips200_show_int(170,250,R_Up_Turn_Right_Point_Position_1,3);
    ips200_show_string(0,270,"Right_Monotonicity");ips200_show_int(170,270,Right_Monotonicity,3);
}
//右环岛的拐点
void Huandao_Left_Page2(void)
{
    ips200_show_string(0,130,"L_Up_T_Le_F_1");ips200_show_int(170,130,L_Up_Turn_Left_Point_Flag_1,1);
    ips200_show_string(0,150,"L_R_T_Up_Flag_1");ips200_show_int(170,150,L_Right_Turn_Up_Point_Flag_1,1);
    ips200_show_string(0,170,"R_Up_T_R_Flag_1");ips200_show_int(170,170,R_Up_Turn_Right_Point_Flag_1,1);
    ips200_show_string(0,190,"R_L_T_Up_Flag_1");ips200_show_int(170,190,R_Left_Turn_Up_Point_Flag_1,1);
    ips200_show_string(0,210,"L_Up_T_L_Point_1");ips200_show_int(170,210,L_Up_Turn_Left_Point_1[1],3);
    ips200_show_string(0,230,"L_R_T_Up_Point_1");ips200_show_int(170,230,L_Right_Turn_Up_Point_1[1],3);
    ips200_show_string(0,250,"R_U_T_Rt_Point_1");ips200_show_int(170,250,R_Up_Turn_Right_Point_1[1],3);
    ips200_show_string(0,270,"R_L_T_Up_Point_1");ips200_show_int(170,270,R_Left_Turn_Up_Point_1[1],3);
}
int Menue_Page_Num_Index=0;//数据下标
//显示光标
void Shpw_Points()
{
    ips200_show_string(Menue_Chos[Menue_Page_Num_Index].Title_X,Menue_Chos[Menue_Page_Num_Index].Title_Y,"<-");//显示光标
}
/*********************************************可调的参数*****************************************************************/
//可该参数的菜单
//PID参数，测试
void Change_Pid(void)
{
    ips200_show_string(Menue_Chos[0].String_X,Menue_Chos[0].String_Y,"L_Kp");ips200_show_float(Menue_Chos[0].Digital_X,Menue_Chos[0].Digital_Y,(*PID[0].Num),3,2);
    ips200_show_string(Menue_Chos[1].String_X,Menue_Chos[1].String_Y,"L_Ki");ips200_show_float(Menue_Chos[1].Digital_X,Menue_Chos[1].Digital_Y,(*PID[1].Num),3,2);
    ips200_show_string(Menue_Chos[2].String_X,Menue_Chos[2].String_Y,"L_Kd");ips200_show_float(Menue_Chos[2].Digital_X,Menue_Chos[2].Digital_Y,(*PID[2].Num),3,2);
    ips200_show_string(Menue_Chos[3].String_X,Menue_Chos[3].String_Y,"R_Kp");ips200_show_float(Menue_Chos[3].Digital_X,Menue_Chos[3].Digital_Y,(*PID[3].Num),3,2);
    ips200_show_string(Menue_Chos[4].String_X,Menue_Chos[4].String_Y,"R_Ki");ips200_show_float(Menue_Chos[4].Digital_X,Menue_Chos[4].Digital_Y,(*PID[4].Num),3,2);
    ips200_show_string(Menue_Chos[5].String_X,Menue_Chos[5].String_Y,"R_Kd");ips200_show_float(Menue_Chos[5].Digital_X,Menue_Chos[5].Digital_Y,(*PID[5].Num),3,2);
    ips200_show_string(Menue_Chos[6].String_X,Menue_Chos[6].String_Y,"S_Kp");ips200_show_float(Menue_Chos[6].Digital_X,Menue_Chos[6].Digital_Y,(*PID[6].Num),3,2);
    ips200_show_string(Menue_Chos[7].String_X,Menue_Chos[7].String_Y,"S_Ki");ips200_show_float(Menue_Chos[7].Digital_X,Menue_Chos[7].Digital_Y,(*PID[7].Num),3,2);
    ips200_show_string(Menue_Chos[8].String_X,Menue_Chos[8].String_Y,"S_Kd");ips200_show_float(Menue_Chos[8].Digital_X,Menue_Chos[8].Digital_Y,(*PID[8].Num),3,2);
}
//速度
void Change_Speed(void)
{
    ips200_show_string(Menue_Chos[0].String_X,Menue_Chos[0].String_Y,"Auto_Speed_Flag");ips200_show_int(Menue_Chos[0].Digital_X,Menue_Chos[0].Digital_Y,(*Speed[0].Num),3);
    ips200_show_string(Menue_Chos[1].String_X,Menue_Chos[1].String_Y,"Speed");ips200_show_int(Menue_Chos[1].Digital_X,Menue_Chos[1].Digital_Y,(*Speed[1].Num),3);
    ips200_show_string(Menue_Chos[2].String_X,Menue_Chos[2].String_Y,"BiZhang_Max_S");ips200_show_int(Menue_Chos[2].Digital_X,Menue_Chos[2].Digital_Y,(*Speed[2].Num),3);
    ips200_show_string(Menue_Chos[3].String_X,Menue_Chos[3].String_Y,"R_Huandao_Max_S");ips200_show_int(Menue_Chos[3].Digital_X,Menue_Chos[3].Digital_Y,(*Speed[3].Num),3);
    ips200_show_string(Menue_Chos[4].String_X,Menue_Chos[4].String_Y,"L_Huandao_Max_S"); ips200_show_int(Menue_Chos[4].Digital_X,Menue_Chos[4].Digital_Y,(*Speed[4].Num),3);
    ips200_show_string(Menue_Chos[5].String_X,Menue_Chos[5].String_Y,"Podao_Max_S");ips200_show_int(Menue_Chos[5].Digital_X,Menue_Chos[5].Digital_Y,(*Speed[5].Num),3);
    ips200_show_string(Menue_Chos[6].String_X,Menue_Chos[6].String_Y,"WanDao_Max_S");ips200_show_int(Menue_Chos[6].Digital_X,Menue_Chos[6].Digital_Y,(*Speed[6].Num),3);
    ips200_show_string(Menue_Chos[7].String_X,Menue_Chos[7].String_Y,"ZhiDao_Speed");ips200_show_int(Menue_Chos[7].Digital_X,Menue_Chos[7].Digital_Y,(*Speed[7].Num),3);
}
//元素标志位
void Change_YuanSu_Flag(void)
{
    ips200_show_string(Menue_Chos[0].String_X,Menue_Chos[0].String_Y,"Shizi_Key");ips200_show_int(Menue_Chos[0].Digital_X,Menue_Chos[0].Digital_Y,(*YuanSu_Flag[0].Num),1);
    ips200_show_string(Menue_Chos[1].String_X,Menue_Chos[1].String_Y,"BanMa_Flag");ips200_show_int(Menue_Chos[1].Digital_X,Menue_Chos[1].Digital_Y,(*YuanSu_Flag[1].Num),1);
    ips200_show_string(Menue_Chos[2].String_X,Menue_Chos[2].String_Y,"Huandao_Key");ips200_show_int(Menue_Chos[2].Digital_X,Menue_Chos[2].Digital_Y,(*YuanSu_Flag[2].Num),1);
    ips200_show_string(Menue_Chos[3].String_X,Menue_Chos[3].String_Y,"Podao_Key");ips200_show_int(Menue_Chos[3].Digital_X,Menue_Chos[3].Digital_Y,(*YuanSu_Flag[3].Num),1);
    ips200_show_string(Menue_Chos[4].String_X,Menue_Chos[4].String_Y,"WanDao_Key");ips200_show_int(Menue_Chos[4].Digital_X,Menue_Chos[4].Digital_Y,(*YuanSu_Flag[4].Num),1);
    ips200_show_string(Menue_Chos[5].String_X,Menue_Chos[5].String_Y,"BiZhang_Key");ips200_show_int(Menue_Chos[5].Digital_X,Menue_Chos[5].Digital_Y,(*YuanSu_Flag[5].Num),1);
}
void Change_TuXiang(void)
{
    ips200_show_string(Menue_Chos[0].String_X,Menue_Chos[0].String_Y,"VALUE_Key");ips200_show_int(Menue_Chos[0].Digital_X,Menue_Chos[0].Digital_Y,(*DAjin[0].Num),1);
    ips200_show_string(Menue_Chos[1].String_X,Menue_Chos[1].String_Y,"threshold_value");ips200_show_int(Menue_Chos[1].Digital_X,Menue_Chos[1].Digital_Y,(*DAjin[1].Num),3);
    ips200_show_string(Menue_Chos[2].String_X,Menue_Chos[2].String_Y,"brightness");ips200_show_int(Menue_Chos[2].Digital_X,Menue_Chos[2].Digital_Y,(*DAjin[2].Num),3);
}
/*********************************************菜单的按键控制*****************************************************************/

int FaChe_Stace=0;

int Menue_Cap=0;//菜单选择，，初始化位不可调菜单
int Menue_Page_Index=6;//菜单索引
int Imu_Get_Stastic=0;//获取零漂数据
int FuYa_Key=0;
void Page_Control(void)
{
    int Switch_stase=0;
    int key_value=0;
    Switch_stase=Get_SwitchValue();//获取拨码开关数据
    key_value=Get_KeyValue();//获取按键数据
    ips200_show_int(190,0,Switch_stase,1);//显示拨码开关状态
    ips200_show_int(190,20,Menue_Page_Index+1,1);//显示菜单页数
    ips200_show_int(190,40,Menue_Cap,5);//显示菜单选项
    ips200_show_int(190,60,battery_vol,5);//显示电压值
    ips200_show_int(190,80,Imu_Get_Stastic,5);//获取陀螺仪零漂
    if(Switch_stase==1)
    {
        if(key_value==1)//菜单页数加一
        {
            Menue_Page_Index++;
            Menue_Page_Index=Menue_Page_Index%10;
            ips200_clear();//每次更新都要进行一次清屏
        }
        else if(key_value==2)//菜单页数减一
        {
            Menue_Page_Index--;
           if(Menue_Page_Index<0)Menue_Page_Index=9; 
           ips200_clear();//每次更新都要进行一次清屏
        }
        else if(key_value==3)//状态机清零
        {
            HuanDao_Stas=0;//将环岛状态清零，，临时使用
        }
        else if (key_value==4)//调整显示的菜单，，0不可调参菜单，1可调参菜单，，变更菜单时会将下标清零
        {
            Menue_Page_Index=0;
            Menue_Cap++;//菜单选择
            Menue_Cap=Menue_Cap%2;
            ips200_clear();//每次更新都要进行一次清屏
        }
    }
    else if(Switch_stase==2)
    {
        if(key_value==1)
        {
            FaChe_Stace=1;
            FaChe_Stace=FaChe_Stace%2;
            // CAR_RUN++;//发车，，停车
            // CAR_RUN=CAR_RUN%2;
            // BanMaXianTime=0;
        }
        else if (key_value==2)//发车前将所有标志位清零
        {
            // BiZhang_Stace=0;
            // Imu_Get_Stastic=1;
            HuanDao_Stas=0;//将环岛状态清零
            // Clear_Gyroscope_Pitch();
            // Clear_Gyroscope_Angle();
        }
        else if (key_value==3)//获取陀螺仪零漂
        {
            FuYa_Key++;
            FuYa_Key=FuYa_Key%2;
        }
        else if (key_value==4)
        {
            pwm_set_duty(SERVO_MOTOR1_PWM, 4163);
            CAR_RUN2=0;
            Right_OUT=0;
            Moter_Right.PWM_OUT=0;
        }
    }
    else if(Switch_stase==3)//状态3可以更改参数，，目前只有PID参数可更改
    {
        if(key_value==1)//调整光标位置，，线下移动
        {
            Menue_Page_Num_Index++;
            Menue_Page_Num_Index=Menue_Page_Num_Index%Page_Num_MAX;
            ips200_clear();//每次更新都要进行一次清屏
        }
        else if(key_value==2)//向上移动
        {
            Menue_Page_Num_Index--;
            if(Menue_Page_Num_Index<0)
            {
                Menue_Page_Num_Index=Page_Num_MAX-1;
            }
            ips200_clear();//每次更新都要进行一次清屏
        }
        else if(key_value==3)//调整数值加
        {
            if(Change_Menue[Menue_Page_Index].data == "Change_Pid")
            {
                (*PID[Menue_Page_Num_Index].Num)=(*PID[Menue_Page_Num_Index].Num)+0.01;
            }
            else if (Change_Menue[Menue_Page_Index].data == "Change_Speed")
            {
                if(Speed[Menue_Page_Num_Index].data=="Auto_Speed_Flag")
                {
                    (*Speed[Menue_Page_Num_Index].Num)=(*Speed[Menue_Page_Num_Index].Num)+1;
                    (*Speed[Menue_Page_Num_Index].Num)=(*Speed[Menue_Page_Num_Index].Num)%2;
                }
                else
                {
                    (*Speed[Menue_Page_Num_Index].Num)=(*Speed[Menue_Page_Num_Index].Num)+10;
                }
            }
            else if (Change_Menue[Menue_Page_Index].data == "Change_YuanSu_Flag")
            {
                (*YuanSu_Flag[Menue_Page_Num_Index].Num)=(*YuanSu_Flag[Menue_Page_Num_Index].Num)+1;
                (*YuanSu_Flag[Menue_Page_Num_Index].Num)=(*YuanSu_Flag[Menue_Page_Num_Index].Num)%2;
            }
            else if(Change_Menue[Menue_Page_Index].data == "Change_TuXiang")
            {
                if(DAjin[Menue_Page_Num_Index].data=="threshold_value")
                {
                    (*DAjin[Menue_Page_Num_Index].Num)=(*DAjin[Menue_Page_Num_Index].Num)+1;
                    (*DAjin[Menue_Page_Num_Index].Num)=(*DAjin[Menue_Page_Num_Index].Num)%255;
                }
                else if(DAjin[Menue_Page_Num_Index].data=="brightness")
                {
                    (*DAjin[Menue_Page_Num_Index].Num)=(*DAjin[Menue_Page_Num_Index].Num)+1;
                    (*DAjin[Menue_Page_Num_Index].Num)=(*DAjin[Menue_Page_Num_Index].Num)%255;
                }
                else
                {
                    (*DAjin[Menue_Page_Num_Index].Num)=(*DAjin[Menue_Page_Num_Index].Num)+1;
                    (*DAjin[Menue_Page_Num_Index].Num)=(*DAjin[Menue_Page_Num_Index].Num)%2;
                }
            }
        }
        else if(key_value==4)//调整数值减
        {
            if(Change_Menue[Menue_Page_Index].data == "Change_Pid")
            {
                (*PID[Menue_Page_Num_Index].Num)=(*PID[Menue_Page_Num_Index].Num)-0.01;
            }
            else if (Change_Menue[Menue_Page_Index].data == "Change_Speed")
            {
                if(Speed[Menue_Page_Num_Index].data=="Auto_Speed_Flag")
                {
                    (*Speed[Menue_Page_Num_Index].Num)=(*Speed[Menue_Page_Num_Index].Num)-1;
                    if((*Speed[Menue_Page_Num_Index].Num)<0)
                    {
                        (*Speed[Menue_Page_Num_Index].Num)=1;
                    }
                }
                else
                {
                    (*Speed[Menue_Page_Num_Index].Num)=(*Speed[Menue_Page_Num_Index].Num)-10;
                }
            }
            else if (Change_Menue[Menue_Page_Index].data == "Change_YuanSu_Flag")
            {
                (*YuanSu_Flag[Menue_Page_Num_Index].Num)=(*YuanSu_Flag[Menue_Page_Num_Index].Num)-1;
                if((*YuanSu_Flag[Menue_Page_Num_Index].Num)<0)
                {
                    (*YuanSu_Flag[Menue_Page_Num_Index].Num)=1;
                }
            }
            else if(Change_Menue[Menue_Page_Index].data == "Change_TuXiang")
            {
                if(DAjin[Menue_Page_Num_Index].data=="threshold_value")
                {
                    (*DAjin[Menue_Page_Num_Index].Num)=(*DAjin[Menue_Page_Num_Index].Num)-1;
                    if((*DAjin[Menue_Page_Num_Index].Num)<0)
                    {
                        (*DAjin[Menue_Page_Num_Index].Num)=255;
                    }
                }
                else if(DAjin[Menue_Page_Num_Index].data=="brightness")
                {
                    (*DAjin[Menue_Page_Num_Index].Num)=(*DAjin[Menue_Page_Num_Index].Num)-1;
                    if((*DAjin[Menue_Page_Num_Index].Num)<-500)
                   {
                        (*DAjin[Menue_Page_Num_Index].Num)=0;
                   }
                }
                else
                {
                    (*DAjin[Menue_Page_Num_Index].Num)=(*DAjin[Menue_Page_Num_Index].Num)-1;
                   if((*DAjin[Menue_Page_Num_Index].Num)<0)
                   {
                        (*DAjin[Menue_Page_Num_Index].Num)=2;
                   }
                }
            }
        }
    }
    else if(Switch_stase==4)
    {
        if(key_value==1)
        {
            int i=0;
            for(i=hightest;i<start_point_l[1];i++)
            {
                printf("%d,",Zhi_Dao_KuanDu[i]);
            }
        }
    }
}
//
int I_qingling=0;
extern int Read_Car_Run;
int Car_Image=0;
void Menue_Show()
{
    //读取按键信息
    Page_Control();
    //控制菜单显示
    if(CAR_RUN==0)
    {
        if(Menue_Cap==0)
        {
            if(MENUE[Menue_Page_Index].fun != NULL)//不可调参的菜单显示，，可调参的未显示，，修改不同的显示菜单只需要改结构体类型即可
            {
                MENUE[Menue_Page_Index].fun();//显示菜单
            }
        }
        else if (Menue_Cap==1)
        {
            if(Change_Menue[Menue_Page_Index].fun != NULL)//可调参的菜单显示
            {
                Change_Menue[Menue_Page_Index].fun();//显示菜单
                Shpw_Points();//光标显示
            }
        }
    }
    //发车状态处理
    if(FaChe_Stace==1)
    {
        Clear_Gyroscope_Pitch();
        Clear_Gyroscope_Angle();
        FuYa_Key=1;
        Imu_Get_Stastic=1;
        if(Read_Car_Run==1)
        {
            Car_Image++;
            if(Car_Image>10)
            {
                I_qingling=1;
                CAR_RUN=1;
                FaChe_Stace=0;
                Read_Car_Run=0;
                Car_Image=0;
            }
        }
    }
}